import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { AccountPasswordAuthServiceApi,
AccountPasswordAuthService_getAccountResult,
AccountPasswordAuthService_getAccountVariables,
AccountPasswordAuthService_loginResult,
AccountPasswordAuthService_loginVariables,
AccountPasswordAuthService_listResult,
AccountPasswordAuthService_listVariables,
AccountPasswordAuthService_totalCountResult,
AccountPasswordAuthService_searchResult,
AccountPasswordAuthService_searchVariables,
AccountPasswordAuthService_loadAllResult,
AccountPasswordAuthService_getByIdResult,
AccountPasswordAuthService_getByIdVariables,
AccountPasswordAuthService_saveResult,
AccountPasswordAuthService_saveVariables,
AccountPasswordAuthService_removeByIdResult,
AccountPasswordAuthService_removeByIdVariables,
AccountPasswordAuthService_removeByIdListResult,
AccountPasswordAuthService_removeByIdListVariables,
AuthAccountResultInfo, AuthAccountPageInfo,
AuthAccountConnection,
AuthAccountPackage,
AuthAccountOrderBy,
AuthAccountMutationInfo,
AuthAccountStringFilter,
AuthAccountNumberFilter,
AuthAccountBooleanFilter,
accountPasswordAuthServiceQuery,
accountPasswordAuthServiceMutation,
AccountPasswordAuthServiceQueryOptions,
AccountStore,
ProfileViewView,
AccountInput,
AccountFilter,
TenantView,
AuthAccountErrorBody} from '../model/account_password_auth_service.model';

/************************************************************************
 * 用户认证
 */
@Injectable({
    providedIn: 'root'
})
export class AccountPasswordAuthService implements AccountPasswordAuthServiceApi {

        private getAccountGql:string;
        private loginGql:string;
        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<AccountPasswordAuthService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.getAccountGql=`query aap_accountPasswordAuthService_getAccount($token: String){${accountPasswordAuthServiceQuery.accountPasswordAuthService_getAccount}}`;
        this.loginGql=`query aap_accountPasswordAuthService_login($tenantCode: String!,$account: String!,$password: String!){${accountPasswordAuthServiceQuery.accountPasswordAuthService_login}}`;
        this.listGql=`query aap_accountPasswordAuthService_list($filter: AccountFilter!,$orderBy: OrderBy){${accountPasswordAuthServiceQuery.accountPasswordAuthService_list}}`;
        this.totalCountGql=`query aap_accountPasswordAuthService_totalCount{${accountPasswordAuthServiceQuery.accountPasswordAuthService_totalCount}}`;
        this.searchGql=`query aap_accountPasswordAuthService_search($first: Int!,$offset: Float!,$filter: AccountFilter!,$orderBy: OrderBy){${accountPasswordAuthServiceQuery.accountPasswordAuthService_search}}`;
        this.searchObjectRef = apollo.watchQuery<AccountPasswordAuthService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query aap_accountPasswordAuthService_loadAll{${accountPasswordAuthServiceQuery.accountPasswordAuthService_loadAll}}`;
        this.getByIdGql=`query aap_accountPasswordAuthService_getById($id: String!){${accountPasswordAuthServiceQuery.accountPasswordAuthService_getById}}`;
    }
    /**
     * 获取登陆信息
     */
    getAccount(variables: AccountPasswordAuthService_getAccountVariables, options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_getAccountResult>> {
            return this.apollo.query({ query: gql`${this.getAccountGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 登陆验证
     */
    login(variables: AccountPasswordAuthService_loginVariables, options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_loginResult>> {
            return this.apollo.query({ query: gql`${this.loginGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 分页查询
     */
    list(variables: AccountPasswordAuthService_listVariables, options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: AccountPasswordAuthService_searchVariables, options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: AccountPasswordAuthService_getByIdVariables, options:AccountPasswordAuthServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<AccountPasswordAuthService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 保存对象
     */
    save(variables: AccountPasswordAuthService_saveVariables): Observable<FetchResult<AccountPasswordAuthService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountPasswordAuthService_save($entity: AccountInput!){${accountPasswordAuthServiceMutation.accountPasswordAuthService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: AccountPasswordAuthService_removeByIdVariables): Observable<FetchResult<AccountPasswordAuthService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountPasswordAuthService_removeById($id: String!){${accountPasswordAuthServiceMutation.accountPasswordAuthService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: AccountPasswordAuthService_removeByIdListVariables): Observable<FetchResult<AccountPasswordAuthService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation aap_accountPasswordAuthService_removeByIdList($ids: [String]!){${accountPasswordAuthServiceMutation.accountPasswordAuthService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
